package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.mscyb.bean.JqwbMachinemaintenancedetail;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqwbMachinemaintenancedetailMapper;
import com.jy.adscm.operation.mscyb.service.JqwbMachinemaintenancedetailService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-07
 */
@Service
public class JqwbMachinemaintenancedetailServiceImpl extends ServiceImpl<JqwbMachinemaintenancedetailMapper, JqwbMachinemaintenancedetail> implements JqwbMachinemaintenancedetailService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public List<JqwbMachinemaintenancedetail> selectByTid(String tid) {
        Wrapper<JqwbMachinemaintenancedetail> wrapper=new EntityWrapper<>();
        wrapper.eq("TID",tid);
        List<JqwbMachinemaintenancedetail> jqwbMachinemaintenancedetails = super.selectList(wrapper);
        for (JqwbMachinemaintenancedetail jqwbMachinemaintenancedetail : jqwbMachinemaintenancedetails) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqwbMachinemaintenancedetail.getRepairer(),null)){
                JyUser jyUser = jyUserMapper.selectById(jqwbMachinemaintenancedetail.getRepairer());
                if(jyUser==null){
                    jqwbMachinemaintenancedetail.setRepairerName(jqwbMachinemaintenancedetail.getRepairer());
                }else {
                    jqwbMachinemaintenancedetail.setRepairerName(jyUser.getName());
                }
            }
        }
        return jqwbMachinemaintenancedetails;
    }
}
